home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / misc / module.c < prev    next >
C/C++ Source or Header  |  1996-08-03  |  2KB  |  111 lines

  1. #pragma implementation
  2. /* #Specification: modules / elf only
  3.     Module support in linuxconf only work for ELF systems.
  4. */
  5. #ifndef LINUXCONF_AOUT
  6.     #include <dlfcn.h>
  7. #endif
  8. #include "misc.h"
  9. #include "module.h"
  10.  
  11. class LINUXCONF_MODULES: public ARRAY{
  12.     /*~PROTOBEG~ LINUXCONF_MODULES */
  13. public:
  14.     LINUXCONF_MODULE *getitem (int no);
  15.     /*~PROTOEND~ LINUXCONF_MODULES */
  16. };
  17.  
  18. PUBLIC LINUXCONF_MODULE *LINUXCONF_MODULES::getitem(int no)
  19. {
  20.     return (LINUXCONF_MODULE*)ARRAY::getitem(no);
  21. }
  22.  
  23. static LINUXCONF_MODULES modules;
  24.  
  25. PUBLIC LINUXCONF_MODULE::LINUXCONF_MODULE()
  26. {
  27.     modules.add (this);
  28. }
  29.  
  30. PUBLIC LINUXCONF_MODULE::~LINUXCONF_MODULE()
  31. {
  32.     modules.remove (this);
  33. }
  34.  
  35. /*
  36.     Let the module add its own option to one menu.
  37.     The "context" let the module identify which dialog it is
  38.     The module is not forced to add options to the menu.
  39. */
  40. PUBLIC VIRTUAL void LINUXCONF_MODULE::setmenu (
  41.     DIALOG &,
  42.     MENU_CONTEXT)
  43. {
  44. }
  45.  
  46. /*
  47.     Check if the user has selected one menu option related to this module
  48.     Do nothing most of the time.
  49. */
  50. PUBLIC VIRTUAL void LINUXCONF_MODULE::domenu (
  51.     MENU_CONTEXT,        // context
  52.     const char *)        // key
  53. {
  54. }
  55.  
  56. /*
  57.     Check if any module has something to add to this menu
  58. */
  59. void module_setmenu (DIALOG &dia, MENU_CONTEXT context)
  60. {
  61.     int n = modules.getnb();
  62.     for (int i=0; i<n; i++) modules.getitem(i)->setmenu (dia,context);
  63. }
  64. /*
  65.     Probe the module for some update after configuration changes.
  66. */
  67. int module_probe (
  68.     int state,        // networking level 0, 1 or 2
  69.                     // at which state are we checking
  70.     int target)        // idem, but the target of the general probe
  71. {
  72.     int ret = 0;
  73.     int n = modules.getnb();
  74.     for (int i=0; i<n; i++){
  75.         if (modules.getitem(i)->probe (state,target)==-1){
  76.             ret = -1;
  77.             break;
  78.         }
  79.     }
  80.     return 0;
  81. }
  82.  
  83. /*
  84.     Check if any module has something to do with this menu selection.
  85. */
  86. void module_domenu (MENU_CONTEXT context, const char *key)
  87. {
  88.     int n = modules.getnb();
  89.     for (int i=0; i<n; i++) modules.getitem(i)->domenu (context,key);
  90. }
  91.  
  92. void module_config()
  93. {
  94. }
  95.  
  96. static const char MODULE[]="module";
  97. static const char LIST[]="list";
  98. void module_load ()
  99. {
  100.     #ifndef LINUXCONF_AOUT
  101.         SSTRINGS tb;
  102.         linuxconf_getall (MODULE,LIST,tb,0);
  103.         int n = tb.getnb();
  104.         for (int i=0; i<n; i++){
  105.             SSTRING *s = tb.getitem(i);
  106.             dlopen (s->get(),RTLD_LAZY);
  107.         }
  108.     #endif
  109. }
  110.  
  111.